<?php
class reportForm extends sfFormSymfony
{
  public function configure()
  {
    $this->setWidget('plant', new sfWidgetFormDoctrineChoice(array(
                                        'model'=>'Plant', 
                                        'add_empty'=>True, 
                                        'multiple'=>False,    
                                        'query' => Doctrine_Query::create()->from('Plant p')->select('id, name')->where('enable=1'),
                                        'default' => $this->getOption("user")->getAttribute("report_plant", false),
                                            ))
                            );
    $this->setValidator('plant',new sfValidatorDoctrineChoice(array(
                                        'model'=>'Plant', 
                                        'multiple'=>true,
                                        'query' => Doctrine_Query::create()->from('Plant p')->select('id, name')->where('enable=1'),
                                        )));
                                         
    
    if ($this->getOption("user")->getAttribute("report_plant", false)){
        
        $plant= Doctrine_Core::getTable('Plant')->find($this->getOption("user")->getAttribute("report_plant"));
        
        
        if ( !(is_object($plant)) || is_null($plant->getPath()) || ( strlen($plant->getPath())<5) ){
            $path=FALSE;
        }  else {
            $path=$plant->getPath();
        }
        
        $this->setWidget('template', new sfWidgetFormInputFile(array(
                                                    )));
        $this->setValidator('template', new sfValidatorFile(array(
                                            'required' => false,
                                             
            )));
        
        
        
        $this->widgetSchema->setHelp("template", ($path===FALSE)? "Select the report file":"<H4>".$path."</H4><BR> This is the default report template file for this plant. To change it click 'Browse' and select a new one");
        
        $this->setWidget('month', new sfWidgetFormDate(array(
                                            'format'=>'%month%/%year%'
            )));
    
        $this->setValidator('month', new sfValidatorDate(array(
                                                'required'=>false,
                                                 )));
    
        $this->widgetSchema->setHelp("month","Select the month");
    
    }
    
    $this->widgetSchema->setHelp("plant","Select the plant");

    
    $this->widgetSchema->setNameFormat('report[%s]');
    
        unset($this->widgetSchema['month']);
  }  
}

